# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=tuning-library
pkgver=1.1.0
pkgrel=2
pkgdesc="Micro-tuning format parsing and frequency finding as a header-only C+ library"
arch=(any)
url="https://surge-synth-team.org/tuning-library/"
license=(MIT)
makedepends=(
  catch2
  cmake
)
source=(
  https://github.com/surge-synthesizer/tuning-library/archive/release_${pkgver}/$pkgname-release_$pkgver.tar.gz
  $pkgname-1.1.0-fix_missing_include.patch
  $pkgname-1.1.0-use_system_catch2.patch
)
sha512sums=('af924f622ffa220e15fcdae54e94fa93ac4fe3a65d8eebecee7a1cdb97458f5686712c08c9262a0d7b6b05521939faf97e3723396b94b125275de68fc29a8e9d'
            '22602ae0b718d0aec7a4577180c9cdce904f5fbfe5347523173cbcaaffac8cd18815e624b86e92152d998b4d8a5fb7b802b4232c16f0afc29afe51a0eb9bac8e'
            '96b5525911a42b43b0e6456307aa7b4b74ea2d2707bae6a4425b64cfedc7e1fcab9c89ace1fa75393cf0a4f684fd7fee6dcbf5988ee86208fbe9e4aa2a3dfeb1')
b2sums=('6a201a08eadc2622e357d75d839d2d101dd1026e112bed6c11240f37aec5a12b1547da453ab88aa48b3da6a0df33dccc71c4d295be6a4ea439a5952db9706abf'
        'c53fd874cb7a1333041e9255e6190a9d58466c7f6797b3a002e4e2aaf6daef4c20101c9b52e3b65439ac1d33f5ec4e23507155f0d14f3b37bad89b5518386b31'
        '99c15cce7388e1bdcd7a349c72449d27760dc7718bc5919d819a1d7420dc0500c9b50bd99fa1d5d56ae80490f2870c05210888659b9a8e3f71a42e299161138a')

prepare() {
  patch -Np1 -d $pkgname-release_$pkgver -i ../$pkgname-1.1.0-fix_missing_include.patch
  patch -Np1 -d $pkgname-release_$pkgver -i ../$pkgname-1.1.0-use_system_catch2.patch
}

build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -S $pkgname-release_$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  make VERBOSE=1 -k run-all-tests -C build
}

package() {
  cd $pkgname-release_$pkgver
  install -vDm 644 include/*.h -t "$pkgdir/usr/include/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
  install -vDm 644 LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname"
}
